package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/rsc/pdf"
	"strconv"
)

func main() {
	fmt.Println("监听本地9097端口")
	gin.SetMode(gin.ReleaseMode)
	router := gin.Default()
	router.GET("/run", func(context *gin.Context) {
		context.JSON(200,gin.H{
			"message":"配置成功",
		})
	})
	router.POST("/getpdfsize", func(context *gin.Context) {
		filePath := context.PostForm("filePath")

		file,err := pdf.Open(string(filePath))
		if(err != nil){
			panic(err)
		}

		numStr := strconv.Itoa(file.NumPage())

		context.JSON(200,gin.H{
			"message":"pdf文件页数",
			"filePath":filePath,
			"pdfSize":numStr,
		})
	})
	router.Run(":9097")
}
